package cn.jbolt.ai.core.chain.node.start;

import cn.jbolt.ai.app.vo.AiChatData;
import cn.jbolt.ai.core.chain.ChainContext;
import cn.jbolt.ai.core.chain.node.provider.CommonNodeProvider;
import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class StartFromUserInputNode implements CommonNodeProvider ,StartNode {
    private static final Logger logger = LoggerFactory.getLogger(StartFromUserInputNode.class);
    @Override
    public void provide(JsonNode nodeConfig, ChainContext context) {

        if (nodeConfig == null || nodeConfig.has("outputField") == false) {
            throw new RuntimeException("开始节点未配置输出字段名");
        }
        String outputField = nodeConfig.get("outputField").asText();
        AiChatData data = context.getSocketData().getDataAsChatData();
        if (data == null || data.getContent() == null) {
            throw new RuntimeException("开始节点未获取到用户输入内容");
        }
        context.setAttr(outputField, context.getSocketData().getDataAsChatData().getContent().getText());


    }
}
